package yicr;

import yicr.panne.CnnModelPredictPane;
import yicr.panne.ImageCreationPane2;
import yicr.panne.SectorScanningPane;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.net.URISyntaxException;

public class MainFrame extends JFrame{

 private static final int DEFAULT_WIDTH=740;
 private static final int DEFAULT_HEIGHT=360;

 public static final boolean whetherLocalRunning=true;

 //放大倍数,会根据屏幕尺寸/1920的倍数，来放大
 private double multiplicationOfSize=1;

 private void setMultiplicationOfSize(){
  Toolkit kit = Toolkit.getDefaultToolkit(); // 定义工具包
  Dimension screenSize = kit.getScreenSize(); // 获取屏幕的尺寸
  multiplicationOfSize=screenSize.width/1920;
 }

 public MainFrame() throws URISyntaxException {
  super("施工材料审核工具-风控部");
  setMultiplicationOfSize();
  initFont();

 }
 
 public void initUI() throws URISyntaxException {
//  this.setBounds(300, 300, 500, 400);
//  setSize(new Dimension(DEFAULT_WIDTH*2,DEFAULT_HEIGHT*2));
  initFont();
  setSize(new Dimension((int) (DEFAULT_WIDTH*multiplicationOfSize), (int) (DEFAULT_HEIGHT*multiplicationOfSize)));
  this.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e) {
    super.windowClosing(e);
    System.exit(0);
   }});
  layoutUI();
  setScreenCenter();
  setResizable(false);
  this.setVisible(true);
 }

 private void initFont(){
  Font f = new Font("宋体", Font.PLAIN, (int) (12*multiplicationOfSize));

  String names[]={ "Label", "CheckBox", "PopupMenu","MenuItem", "CheckBoxMenuItem",
          "JRadioButtonMenuItem","ComboBox", "Button", "Tree", "ScrollPane",
          "TabbedPane", "EditorPane", "TitledBorder", "Menu", "TextArea",
          "OptionPane", "MenuBar", "ToolBar", "ToggleButton", "ToolTip",
          "ProgressBar", "TableHeader", "Panel", "List", "ColorChooser",
          "PasswordField","TextField", "Table", "Label", "Viewport",
          "RadioButtonMenuItem","RadioButton", "DesktopPane", "InternalFrame"
  };
  for (String item : names) {
   UIManager.put(item+ ".font",f);
  }
 }
 
 private void layoutUI() throws URISyntaxException {
 
  //对象实例化
  JTabbedPane tab = new JTabbedPane(JTabbedPane.TOP);
  tab.setFont(new Font("宋体", Font.PLAIN, (int) (12*multiplicationOfSize)));
  //容器
  Container container = this.getLayeredPane();
  //对象化面板
  JPanel combop = new JPanel();
  JPanel p1 = new JPanel();
  JPanel p2 = new JPanel();
  JPanel p3 = new JPanel();
  JPanel p4 = new JPanel();


  SectorScanningPane sectorScanningPane=new SectorScanningPane();
//  ImageCreationPane2 imageCreationPane=new ImageCreationPane2();
//  CnnModelPredictPane cnnModelPredictPane=new CnnModelPredictPane();

  tab.add(sectorScanningPane,"材料核对");
//  tab.add(imageCreationPane,"覆盖图构建");
//  tab.add(cnnModelPredictPane,"CNN模型判别");

  
  container.setLayout(new BorderLayout());
//  container.add(combop,BorderLayout.NORTH);
  container.add(tab,BorderLayout.CENTER);

  
 }

 /**
  * 根据打包或者本地运行， 资源相对路径返回资源的绝对路径
  * @param relativePath 需要带第一个斜杠,\\geohash_2_f.png"
  * @return
  */
 public static String calResourceAbsPath(boolean whetherLocalRun,String relativePath){
   if(whetherLocalRun){
    String resourcePath=Thread.currentThread().getContextClassLoader().getResource("")+relativePath;
    //imageAbsPath=Thread.currentThread().getContextClassLoader().getResource("")+"\\antenna_1.png";
    resourcePath=resourcePath.replace("file:","");
    return resourcePath;
   }else{
    String exePath=new File("").getAbsolutePath();
    return exePath+relativePath;
   }



 }

 private void setScreenCenter(){

  int windowWidth = getWidth(); // 获得窗口宽
  int windowHeight = getHeight(); // 获得窗口高
  Toolkit kit = Toolkit.getDefaultToolkit(); // 定义工具包
  Dimension screenSize = kit.getScreenSize(); // 获取屏幕的尺寸
  int screenWidth = screenSize.width; // 获取屏幕的宽
  int screenHeight = screenSize.height; // 获取屏幕的高
  setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2);// 设置窗口居中显示

 }
 
 
 
 public static void main(String[] args) throws URISyntaxException {
  MainFrame ui = new MainFrame();
  ui.initUI();

  String s="D:\\Python_Projects\\cnn_wireless\\resources\\npy\\images_135_no_additional_points.npy";
}
}